<%@ Page Language="C#"  MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="EditQuestionnaire.aspx.cs" Inherits="Control_EditQuestionnaire" MaintainScrollPositionOnPostback="true" %>
<%@ MasterType VirtualPath="~/Master.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
    <h1>Questionnaire details</h1>
        
    <h2><asp:Literal ID="litQuestionnaire" runat="server"></asp:Literal></h2>
    
    <br />
    
    <div class="formInputTitle">Select a question type:</div>
    <asp:DropDownList ID="ddlQuestionType" runat="server" OnSelectedIndexChanged="ddlQuestionType_SelectedIndexChanged" AutoPostBack="true" CssClass="formInput" onfocus="this.className='formInputOver';" onblur="this.className='formInput';">
    </asp:DropDownList>
        
    <asp:GridView ID="gViewQuestions" runat="server" DataKeyNames="QuestionID,QuestionType_FK" OnRowCommand="gViewQuestions_RowCommand" OnRowCreated="gViewQuestions_RowCreated" OnRowDataBound="gViewQuestions_RowDataBound" OnRowEditing="gViewQuestions_RowEditing" OnRowCancelingEdit="gViewQuestions_RowCancelingEdit" OnRowUpdating="gViewQuestions_RowUpdating" OnRowDeleting="gViewQuestions_RowDeleting"
    AutoGenerateColumns="false" ShowFooter="true">

        <Columns>
                 
            <asp:TemplateField HeaderText="Question">
                <ItemTemplate>
                    <%# Eval("Question").ToString().Replace(Environment.NewLine, "<br/>")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="edit_txtQuestion" TextMode="MultiLine" Text='<%# Eval("Question").ToString().Replace(Environment.NewLine, "<br/>")%>' runat="Server" />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtQuestion" runat="server" TextMode="MultiLine"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
       
            <asp:TemplateField HeaderText="Question order" Visible="true">
                <ItemTemplate>
                    <%# Eval("QuestionOrder")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="edit_txtQuestionOrder" runat="server" Text='<%# Eval("QuestionOrder")%>'></asp:TextBox>
                    <asp:RangeValidator SetFocusOnError="true" ID="RangeValidator1" ControlToValidate="edit_txtQuestionOrder" Type="Integer" MaximumValue="1000"  MinimumValue="1"  runat="server" ErrorMessage="numeric value(1-1000)"></asp:RangeValidator>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtQuestionOrder" runat="server"></asp:TextBox>
                    <asp:RangeValidator SetFocusOnError="true" ID="RangeValidator2" ControlToValidate="txtQuestionOrder" Type="Integer" MaximumValue="1000"  MinimumValue="1" runat="server" ErrorMessage="numeric value(1-1000)"></asp:RangeValidator>
                </FooterTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="LowerText (1)" Visible="true">
                <ItemTemplate>
                    <%# Eval("LowerText")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="edit_txtLowerText" runat="server" Text='<%# Eval("LowerText")%>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtLowerText" runat="server"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            
            <asp:TemplateField HeaderText="UpperText (5)" Visible="true">
                <ItemTemplate>
                    <%# Eval("UpperText")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="edit_txtUpperText" runat="server" Text='<%# Eval("UpperText")%>'></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtUpperText" runat="server" ></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
                    
            <asp:TemplateField>
                <ItemTemplate>
                 <asp:LinkButton ID="linkBtnAddOptions" Visible="false" runat="server" CommandName="Expand">Add Options</asp:LinkButton>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Button ID="btnAdd" runat="server" Text="Add" CommandName="Add" />
                </FooterTemplate>
            </asp:TemplateField>
            
            <asp:CommandField ShowEditButton="True"  ButtonType="Link" UpdateText="Update" HeaderText="Edit" CancelText="Cancel" EditText="Edit" />
    						
            <asp:CommandField ShowDeleteButton="True" HeaderText="Delete" />
            
            <asp:TemplateField>

                <ItemTemplate>
</td></tr>
					<tr>
					<td colspan="6">
                    <asp:PlaceHolder ID="Expanded" Runat="server" Visible="False">
                    

                        <asp:GridView ID="gViewOptions" runat="server" AutoGenerateColumns="False" DataKeyNames="OptionID,QuestionID_FK" EnableViewState=true OnRowCommand="gViewOptions_RowCommand" OnRowEditing="gViewOptions_RowEditing" OnRowCancelingEdit="gViewOptions_RowCancelingEdit" OnRowUpdating="gViewOptions_RowUpdating" OnRowDeleting="gViewOptions_RowDeleting"
                            ShowFooter="true" >

                            <Columns>

                                <asp:TemplateField HeaderText="OptionText">
                                    <ItemTemplate>
                                        <%# Eval("OptionText").ToString().Replace(Environment.NewLine, "<br/>")%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="Edit_txtOptionText" runat="server" Text='<%# Eval("OptionText").ToString().Replace(Environment.NewLine, "<br/>")%>' TextMode="MultiLine" Columns="35"></asp:TextBox>
                                    </EditItemTemplate>
                                    <FooterTemplate>
                                        <asp:TextBox ID="txtOptionText" runat="server" TextMode="MultiLine"></asp:TextBox>
                                    </FooterTemplate>
                                </asp:TemplateField>
                    
                                <asp:CommandField ShowEditButton="True"  ButtonType="Link" UpdateText="Update" HeaderText="Edit" CancelText="Cancel" EditText="Edit" />

                                <asp:TemplateField HeaderText="Delete">
                                    <ItemTemplate>
                                        <asp:LinkButton CommandName="Delete" Text="Delete" ID="linkBtnDelete" Runat="server"></asp:LinkButton>  
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        <asp:Button ID="btnAddOptions" runat="server" Text="AddOptions" CommandName="AddOptions" />
                                    </FooterTemplate>
                                </asp:TemplateField>
                                
                            </Columns>
                            
                        </asp:GridView>
                        
                    </asp:PlaceHolder>
                    
                </ItemTemplate>
                
            </asp:TemplateField>
            
        </Columns>
        
    </asp:GridView>

</asp:Content>